//
//  UIBarButtonItem+Extension.swift
//  SLBlog
//
//  Created by 盼 on 2017/11/30.
//  Copyright © 2017年 pan. All rights reserved.
//

import UIKit

extension UIBarButtonItem
{
    
    /// 扩展UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize
    ///   - target: targrt
    ///   - action: action
    convenience init(title: String, fontSize: CGFloat = 16, target: Any, action: Selector, isBack: Bool = false) {
        
        let btn = UIButton(type: UIButtonType.custom)
        btn.setTitle(title, for: UIControlState.normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        btn.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
        btn.setTitleColor(UIColor.orange, for: UIControlState.highlighted)
        btn.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            
            btn.setImage(UIImage.init(named: imageName), for: UIControlState.normal)
            btn.setImage(UIImage.init(named: imageName+"_highlighted"), for: UIControlState.highlighted)
        }
        btn.sizeToFit()
        
        self.init(customView: btn)
    }
}
